//2020年6月14日23:06:57
//========================================初始化开始=================================================//
//屏幕分辨率检测
Dim screenX = GetScreenX()
Dim screenY = GetScreenY()
SetRowsNumber(33)
SetOffsetInterval (1)
SetDictEx 1, "Attachment:mq_soft.txt"
UseDict (1)
TracePrint "分辨率: "&screenX&"*" &screenY
Log.Open 
TracePrint "当前设备的临时目录为：" &GetTempDir()
Dim auto_bool = ReadUIConfig("auto")
Dim watering_bool = ReadUIConfig("watering")
Call Screen()//屏幕适配 
Call main()

//主函数
Function main
    //自动进入界面
    If auto_bool = True Then 
        Call init()
        
    Else 
        //成功进入
        Delay 4000
    End If
    
    //成功进入
    Delay 2000
    TracePrint "已经进入到界面"
    
    //点击领取
    Call touchConfirm()
    Delay RndEx(1050, 1500)
    //签到
    Call getSign()
    //每日领取
    Call getDayWater()
    
    //领水滴
    Call getWaterDrops()
    
    
    //浇水10次
    If watering_bool = True Then 
        Call watering()
        //领水滴
        Call getWaterDrops()
    End If
    KeyPress "Home"

End Function
//初始函数
Function init
    Dim error_time =0
    TracePrint "进入到界面"
    //进入到界面
    While CmpColorEx("973|2036|2D2D2E",1) = 0
        TracePrint "正在进入到界面"
        RunApp "com.jingdong.app.mall"
        Delay 3000
        
        error_time = error_time + 1
        If error_time > 10 Then 
            TracePrint"出错"
            Exit Function
        End If
    Wend
    //进入我的京东
    TracePrint "进入我的京东"
    error_time =0
    Do
        Touch RndEx(970+5, 970+15), RndEx(2040+5, 2040+15), RndEx(30, 55)
        Delay 2000
        error_time = error_time + 1
        If error_time > 10 Then 
            TracePrint"出错"
            Exit Function
        End If
    Loop While CmpColorEx("973|2036|2D2D2E",1) = 1

    //进入东东牧场
    TracePrint "进入东东农场"
    error_time =0
    Dim intX,intY
    Do
        FindColor 35,1203,1071,1896,"EAF8FE",0,1,intX,intY
        TracePrint "识别:x="&intX&"y="&intY
        If intX > -1 Then 
            Touch RndEx(intX+5, intX+15), RndEx(intY+5, intY+15), RndEx(30, 55)
            Delay RndEx(50, 100)
        End If
        Delay 5000
        error_time = error_time + 1
        If error_time > 30 Then 
            TracePrint"出错"
            Exit Function
        End If
    Loop While CmpColorEx("908|1777|652EFF-111111",1) = 0
    TracePrint "成功进入东东农场"
	
End Function

//每日领取
Function getDayWater
    TracePrint "每日领取"
    Dim intX,intY
    FindColor 128,738,205,828,"1458FF-111111",0,1,intX,intY
    If intX > -1 And intY > -1 Then 
        Touch RndEx(158+5, 158+15), RndEx(712+5, 712+15), RndEx(30, 55)
        Delay RndEx(1500, 2500)
	
        //点击领取
        Call touchConfirm()

    End If
    Delay RndEx(1500, 2500)
End Function

//签到
Function getSign
    TracePrint "签到"
    //我知道了
    Call touchConfirm()
    //点击签到
    Dim intX,intY
    FindColor 86,1578,179,1693,"B8EB6E-111111",0,0.9,intX,intY
    If intX > -1 And intY > -1 Then
        Touch RndEx(intX+5, intX+15), RndEx(intY+5, intY+15), RndEx(30, 55)
        Delay RndEx(1050, 1500)
        //点击领取
        Call touchConfirm()
        Delay RndEx(1050, 1500)
        //我知道了
        Call touchConfirm()
        
    End If
	
End Function

//红色方块确认
Function touchConfirm
    //点击红色方块确认
    Dim intX,intY
    FindColor 461,1258,648,1710,"6753F7-051111",0,0.9,intX,intY
    If intX > -1 And intY > -1 Then 
        TracePrint "识别:x="&intX&"y="&intY
        Touch RndEx(intX+5, intX+15), RndEx(intY+5, intY+15), RndEx(30, 55)
        Delay RndEx(200, 400)
    End If
End Function
//领水滴
Function getWaterDrops
    TracePrint "领水滴"
    Dim error_time =0
	
    //进入领水滴
    Call openWaterDrops()
    //成功进入领水滴
    Dim intX,intY	
    Do
    
        //去领取
        Call receive()
        //去收集
        Call collect()
        //去逛逛
        Call stroll()
        
        Swipe screenX / 2, screenY - 50, screenX / 2, screenY/2+200, RndEx(800, 1000)
        Delay RndEx(1800 + 5, 2000 + 115)
        FindColor 792, 1701, 1004, 2135, "CED6E2-111111", 0, 1, intX, intY
        error_time = error_time + 1
        If error_time > 10 Then 
            TracePrint"出错"
            Exit Do
        End If
    Loop While intX = -1
    Delay 2000
    //关闭领水滴
    FindColor 1018,1009,1057,1054,"89B6F3-111111",0,0.9,intX,intY
    If intX > -1 And intY > -1 Then
        TracePrint "识别:x="&intX&"y="&intY
        Touch RndEx(intX+5, intX+15), RndEx(intY+5, intY+15), RndEx(30, 55)
        Delay RndEx(200, 400)
    End If
End Function

//进入领水滴
Function openWaterDrops
    TracePrint "进入领水滴"
    Dim error_time =0
    Do
        Touch RndEx(318+5, 318+15), RndEx(1636+5, 1636+15), RndEx(30, 55)
        Delay RndEx(1500, 2500)
        
        error_time = error_time + 1
        If error_time > 10 Then 
            TracePrint"出错"
            Exit Do
        End If
    Loop While CmpColorEx("318|1636|FFF490-111111",1) = 1

End Function



//去领取
Function receive
    Dim intX,intY
    Do
        FindStr(853,1200,949,2043,"领取","FFFFFF-111111",0.8,intX,intY)
        If intX > -1 And intY > -1 Then 
            Touch RndEx(intX + 5, intX + 15), RndEx(intY + 5, intY + 15), RndEx(30, 55)
            Delay RndEx(1000 + 5, 2000 + 115)
            If CmpColorEx("547|1389|6455F7-111111",1) = 1 Then
                Touch RndEx(547+5, 547+15), RndEx(1389+5, 1389+15), RndEx(30, 55)
                Delay RndEx(50, 100)
            End If
        End If
    Loop While intX > -1
    Delay RndEx(1000 + 5, 2000 + 115)
End Function



//去收集
Function collect
    //todo
    Dim intX,intY
    FindStr(873,1132,949,2043,"收集","FFFFFF-111111",0.9,intX,intY)
    If intX > -1 And intY > -1 Then 
        Touch RndEx(intX + 5, intX + 15), RndEx(intY + 5, intY + 15), RndEx(30, 55)
        Delay RndEx(1000 + 5, 2000 + 115)
        //水滴红包雨
        Call rainDropsRedEnvelopes()
    End If
    //进入领水滴
    Call openWaterDrops()
End Function

//水滴红包雨
Function rainDropsRedEnvelopes
    Delay 3000
    
    Dim intX,intY,intX2,intY2,i=0
    Dim this_task = TickCount()
    Do
    	
        //识别红包
        FindColor 29,479,1068,1006,"5253EB-111111",3,1,intX2,intY2
        If intX2 > -1 And intY2 > -1 Then 
            If i = 0 Then 
                this_task = TickCount()
            End If
        	
            i=i+1
            TracePrint "点击到第"&i&"个红包"
            Touch RndEx(intX2 + 5, intX2 + 15), RndEx(intY2 - 5, intY2 - 15), RndEx(30, 55)
            Delay RndEx(50, 100)
        End If
        
    Loop While TickCount() - this_task < 13*1000
    
     
    //点击返回
    KeyPress "Back"
    Delay RndEx(1000 + 5, 2000 + 115)

End Function 


//去逛逛
Function stroll
    Dim intX,intY
    Do
        FindStr(873,1132,949,2043,"逛逛","FFFFFF-111111",0.9,intX,intY)
        If intX > -1 And intY > -1 Then 
            Touch RndEx(intX + 5, intX + 15), RndEx(intY + 5, intY + 15), RndEx(30, 55)
            Delay RndEx(2000 + 5, 3500 + 115)
            Swipe screenX / 2, screenY - 50, screenX / 2, screenY/2+200, RndEx(800, 1000)
            Delay RndEx(8000 + 5, 10000 + 115)
            KeyPress "Back"
            Delay RndEx(1000 + 5, 1500 + 115)
            //我知道了
            Call touchConfirm()
            //去领取
            Call receive()
        End If
    Loop While intX > -1
    Delay RndEx(1000 + 5, 2000 + 115)
    
End Function

//浇水10次
Function watering
    For 10
        Dim intX,intY
        FindColor 842,1720,978,1794,"652EFF-111111",0,0.9,intX,intY
        If intX > -1 And intY > -1 Then
            TracePrint "识别:x="&intX&"y="&intY
            Touch RndEx(intX + 5, intX + 15), RndEx(intY + 5, intY + 15), RndEx(30, 55)
            Delay RndEx(4000, 5000)
            //点击领取
            Call touchConfirm()
            Delay RndEx(1000, 2000)
        End If
        
    Next
End Function



//适配分辨率
Function Screen
    Dim scrX,scrY
    //这里设置成开发的分辨率
    scrX = 1080
    scrY = 2160
    SetScreenScale scrX, scrY,1
    Dim src = scrX & scrY
End Function


//封装随机数函数
Function RndEx(min, max)
    //Int((最大值 - 最小值 + 1) * Rnd() + 最小值)
    RndEx = Int(((max-min) * Rnd()) + min)
End Function
Function OnScriptExit()
 
    ShowMessage "脚本已经停止！"
    Log.Close 
End Function

